package world

import (
	"server/world/entity"
	"sync/atomic"
)

var npcIDCounter int64 = 0
var monsterIDCounter int64 = 0
var itemIDCounter int64 = 0
var obstacleIDCounter int64 = 0
var playerIDCounter int64 = 0

// NewPlayer 创建新的玩家实体并返回
func NewPlayer() *entity.Player {
	// 生成唯一的玩家ID
	id := atomic.AddInt64(&playerIDCounter, 1)
	// 创建玩家时使用默认的位置(0,0)，之后可以通过SetPosition修改
	player, _ := entity.NewPlayer(int32(id), 0, 0)
	return player
}

// NewNPC 创建新的NPC实体并返回
func NewNPC(name, scriptID, dialogID string, x, y float64) *entity.NPC {
	// 生成唯一的NPC ID
	id := atomic.AddInt64(&npcIDCounter, 1)
	return entity.NewNPC(id, name, scriptID, dialogID, x, y)
}

// NewMonster 创建新的怪物实体并返回
func NewMonster(name string, level, hp, attack, defense int, x, y float64) *entity.Monster {
	// 生成唯一的怪物 ID
	id := atomic.AddInt64(&monsterIDCounter, 1)
	return entity.NewMonster(id, name, level, hp, attack, defense, x, y)
}

// NewItem 创建新的物品实体并返回
func NewItem(itemID string, quantity int, x, y float64) *entity.Item {
	// 生成唯一的物品 ID
	id := atomic.AddInt64(&itemIDCounter, 1)
	return entity.NewItem(id, itemID, quantity, x, y)
}

// NewObstacle 创建新的障碍物实体并返回
func NewObstacle(width, height float64, x, y float64, isStatic bool) *entity.Obstacle {
	// 生成唯一的障碍物 ID
	id := atomic.AddInt64(&obstacleIDCounter, 1)
	return entity.NewObstacle(id, width, height, x, y, isStatic)
}